Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtStreamed As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtDownloaded As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents BtnPremium As System.Windows.Forms.Button Friend WithEvents BtnRegular As System.Windows.Forms.Button Friend WithEvents BtnBasic As System.Windows.Forms.Button Friend WithEvents BtnAll As System.Windows.Forms.Button Friend WithEvents BtnClear As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents TxtPremium As System.Windows.Forms.TextBox Friend WithEvents TxtRegular As System.Windows.Forms.TextBox Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents TxtBasic As System.Windows.Forms.TextBox Friend WithEvents Label8 As System.Windows.Forms.Label Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.Label2 = New System.Windows.Forms.Label Me.TxtStreamed = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.TxtDownloaded = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.BtnPremium = New System.Windows.Forms.Button Me.BtnRegular = New System.Windows.Forms.Button Me.BtnBasic = New System.Windows.Forms.Button Me.BtnAll = New System.Windows.Forms.Button Me.BtnClear = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.GroupBox2 = New System.Windows.Forms.GroupBox Me.Label6 = New System.Windows.Forms.Label Me.TxtPremium = New System.Windows.Forms.TextBox Me.TxtRegular = New System.Windows.Forms.TextBox Me.Label7 = New System.Windows.Forms.Label Me.TxtBasic = New System.Windows.Forms.TextBox Me.Label8 = New System.Windows.Forms.Label Me.GroupBox1.SuspendLayout() Me.GroupBox2.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(344, 32) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(131, 37) Me.Label1.TabIndex = 0 Me.Label1.Text = "E-Tunes" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.Label4) Me.GroupBox1.Controls.Add(Me.TxtDownloaded) Me.GroupBox1.Controls.Add(Me.Label5) Me.GroupBox1.Controls.Add(Me.Label3) Me.GroupBox1.Controls.Add(Me.TxtStreamed) Me.GroupBox1.Controls.Add(Me.Label2) Me.GroupBox1.Location = New System.Drawing.Point(40, 104) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(304, 160) Me.GroupBox1.TabIndex = 1 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Customer Monthly Activity" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(16, 48) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(120, 32) Me.Label2.TabIndex = 0 Me.Label2.Text = "Listened To:" ' 'TxtStreamed ' Me.TxtStreamed.Location = New System.Drawing.Point(128, 48) Me.TxtStreamed.Name = "TxtStreamed" Me.TxtStreamed.Size = New System.Drawing.Size(72, 22) Me.TxtStreamed.TabIndex = 1 Me.TxtStreamed.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(208, 48) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(64, 24) Me.Label3.TabIndex = 2 Me.Label3.Text = "Songs" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(208, 96) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(64, 24) Me.Label4.TabIndex = 5 Me.Label4.Text = "Songs" ' 'TxtDownloaded ' Me.TxtDownloaded.Location = New System.Drawing.Point(128, 96) Me.TxtDownloaded.Name = "TxtDownloaded" Me.TxtDownloaded.Size = New System.Drawing.Size(72, 22) Me.TxtDownloaded.TabIndex = 4 Me.TxtDownloaded.Text = "" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(16, 96) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(120, 32) Me.Label5.TabIndex = 3 Me.Label5.Text = "Saved:" ' 'BtnPremium ' Me.BtnPremium.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.BtnPremium.Location = New System.Drawing.Point(40, 312) Me.BtnPremium.Name = "BtnPremium" Me.BtnPremium.Size = New System.Drawing.Size(112, 32) Me.BtnPremium.TabIndex = 2 Me.BtnPremium.Text = "Premium" ' 'BtnRegular ' Me.BtnRegular.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.BtnRegular.Location = New System.Drawing.Point(168, 312) Me.BtnRegular.Name = "BtnRegular" Me.BtnRegular.Size = New System.Drawing.Size(112, 32) Me.BtnRegular.TabIndex = 3 Me.BtnRegular.Text = "Regular" ' 'BtnBasic ' Me.BtnBasic.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.BtnBasic.Location = New System.Drawing.Point(296, 312) Me.BtnBasic.Name = "BtnBasic" Me.BtnBasic.Size = New System.Drawing.Size(112, 32) Me.BtnBasic.TabIndex = 4 Me.BtnBasic.Text = "Basic" ' 'BtnAll ' Me.BtnAll.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.BtnAll.Location = New System.Drawing.Point(424, 312) Me.BtnAll.Name = "BtnAll" Me.BtnAll.Size = New System.Drawing.Size(112, 32) Me.BtnAll.TabIndex = 5 Me.BtnAll.Text = "Show All" ' 'BtnClear ' Me.BtnClear.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.BtnClear.Location = New System.Drawing.Point(552, 312) Me.BtnClear.Name = "BtnClear" Me.BtnClear.Size = New System.Drawing.Size(112, 32) Me.BtnClear.TabIndex = 6 Me.BtnClear.Text = "Reset" ' 'BtnQuit ' Me.BtnQuit.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.BtnQuit.Location = New System.Drawing.Point(680, 312) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(112, 32) Me.BtnQuit.TabIndex = 7 Me.BtnQuit.Text = "Quit" ' 'GroupBox2 ' Me.GroupBox2.Controls.Add(Me.TxtBasic) Me.GroupBox2.Controls.Add(Me.Label8) Me.GroupBox2.Controls.Add(Me.TxtRegular) Me.GroupBox2.Controls.Add(Me.Label7) Me.GroupBox2.Controls.Add(Me.TxtPremium) Me.GroupBox2.Controls.Add(Me.Label6) Me.GroupBox2.Location = New System.Drawing.Point(400, 104) Me.GroupBox2.Name = "GroupBox2" Me.GroupBox2.Size = New System.Drawing.Size(392, 160) Me.GroupBox2.TabIndex = 8 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "Monthly Cost" ' 'Label6 ' Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.Location = New System.Drawing.Point(48, 32) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(120, 32) Me.Label6.TabIndex = 0 Me.Label6.Text = "Premium " ' 'TxtPremium ' Me.TxtPremium.Location = New System.Drawing.Point(168, 32) Me.TxtPremium.Name = "TxtPremium" Me.TxtPremium.ReadOnly = True Me.TxtPremium.Size = New System.Drawing.Size(96, 22) Me.TxtPremium.TabIndex = 1 Me.TxtPremium.Text = "" ' 'TxtRegular ' Me.TxtRegular.Location = New System.Drawing.Point(168, 72) Me.TxtRegular.Name = "TxtRegular" Me.TxtRegular.ReadOnly = True Me.TxtRegular.Size = New System.Drawing.Size(96, 22) Me.TxtRegular.TabIndex = 3 Me.TxtRegular.Text = "" ' 'Label7 ' Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label7.Location = New System.Drawing.Point(48, 72) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(120, 32) Me.Label7.TabIndex = 2 Me.Label7.Text = "Regular" ' 'TxtBasic ' Me.TxtBasic.Location = New System.Drawing.Point(168, 112) Me.TxtBasic.Name = "TxtBasic" Me.TxtBasic.ReadOnly = True Me.TxtBasic.Size = New System.Drawing.Size(96, 22) Me.TxtBasic.TabIndex = 5 Me.TxtBasic.Text = "" ' 'Label8 ' Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label8.Location = New System.Drawing.Point(48, 112) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(120, 32) Me.Label8.TabIndex = 4 Me.Label8.Text = "Basic" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(872, 400) Me.Controls.Add(Me.GroupBox2) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.BtnClear) Me.Controls.Add(Me.BtnAll) Me.Controls.Add(Me.BtnBasic) Me.Controls.Add(Me.BtnRegular) Me.Controls.Add(Me.BtnPremium) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "E-Tunes" Me.GroupBox1.ResumeLayout(False) Me.GroupBox2.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Const maxStreamed As Integer = 15000 Const maxDownloaded As Integer = 1000 Private Function GetInput(ByRef numStreamed As Integer, ByRef numDown As Integer) As Boolean Dim ok As Boolean = True If IsNumeric(TxtStreamed.Text) Then numStreamed = Convert.ToInt32(TxtStreamed.Text) If (numStreamed >= 0) And (numStreamed <= maxStreamed) Then ' valid - don't need to do anything Else MsgBox("Number of songs listened to must be between 0 and " & maxStreamed) ok = False End If Else MsgBox("Number of songs listened to must be numeric") ok = False End If If IsNumeric(TxtDownloaded.Text) Then numDown = Convert.ToInt32(TxtDownloaded.Text) If (numDown >= 0) And (numDown <= maxDownloaded) Then ' valid - don't need to do anything Else MsgBox("Number of songs saved to disk must be between 0 and " & maxDownloaded) ok = False End If Else MsgBox("Number of songs saved to disk must be numeric") ok = False End If Return ok End Function Private Function costFunct(ByVal actual As Integer, ByVal free As Integer, ByVal extraCost As Double) As Double Dim extra As Integer Dim cost As Double If actual <= free Then Return 0.0 Else extra = actual - free cost = extra * extraCost Return cost End If End Function Private Function premiumCost(ByVal streamed As Integer, ByVal downloaded As Integer) As Double Dim streamCost As Double Dim downloadCost As Double Dim totalCost As Double Const premFreeStream As Integer = 1000 Const premFreeDown As Integer = 100 Const premMonthly As Double = 50.0 Const premMargStream As Double = 0.05 Const premMargDown As Double = 0.5 streamCost = costFunct(streamed, premFreeStream, premMargStream) downloadCost = costFunct(downloaded, premFreeDown, premMargDown) totalCost = premMonthly + streamCost + downloadCost Return totalCost End Function Private Function regularCost(ByVal streamed As Integer, ByVal downloaded As Integer) As Double Dim streamCost As Double Dim downloadCost As Double Dim totalCost As Double Const regFreeStream As Integer = 200 Const regFreeDown As Integer = 10 Const regMonthly As Double = 20.0 Const regMargStream As Double = 0.1 Const regMargDown As Double = 1.0 streamCost = costFunct(streamed, regFreeStream, regMargStream) downloadCost = costFunct(downloaded, regFreeDown, regMargDown) totalCost = regMonthly + streamCost + downloadCost Return totalCost End Function Private Function basicCost(ByVal streamed As Integer, ByVal downloaded As Integer) As Double Dim streamCost As Double Dim downloadCost As Double Dim totalCost As Double Const basicFreeStream As Integer = 100 Const basicFreeDown As Integer = 5 Const basicMonthly As Double = 10.0 Const basicMargStream As Double = 0.2 Const basicMargDown As Double = 2.0 streamCost = costFunct(streamed, basicFreeStream, basicMargStream) downloadCost = costFunct(downloaded, basicFreeDown, basicMargDown) totalCost = basicMonthly + streamCost + downloadCost Return totalCost End Function Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click TxtStreamed.Text = "" TxtDownloaded.Text = "" TxtPremium.Text = "" TxtRegular.Text = "" TxtBasic.Text = "" End Sub Private Sub BtnPremium_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPremium.Click Dim ok As Boolean Dim streamed As Integer Dim downloaded As Integer Dim cost As Double ok = GetInput(streamed, downloaded) If ok Then cost = premiumCost(streamed, downloaded) TxtPremium.Text = cost.ToString("c") End If End Sub Private Sub BtnRegular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRegular.Click Dim ok As Boolean Dim streamed As Integer Dim downloaded As Integer Dim cost As Double ok = GetInput(streamed, downloaded) If ok Then cost = regularCost(streamed, downloaded) TxtRegular.Text = cost.ToString("c") End If End Sub Private Sub BtnBasic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBasic.Click Dim ok As Boolean Dim streamed As Integer Dim downloaded As Integer Dim cost As Double ok = GetInput(streamed, downloaded) If ok Then cost = basicCost(streamed, downloaded) TxtBasic.Text = cost.ToString("c") End If End Sub Private Sub BtnAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAll.Click Dim ok As Boolean Dim streamed As Integer Dim downloaded As Integer Dim cost As Double ok = GetInput(streamed, downloaded) If ok Then cost = premiumCost(streamed, downloaded) TxtPremium.Text = cost.ToString("c") cost = regularCost(streamed, downloaded) TxtRegular.Text = cost.ToString("c") cost = basicCost(streamed, downloaded) TxtBasic.Text = cost.ToString("c") End If End Sub End Class